package com.gduf.lsm.controller;

import com.gduf.lsm.common.Result;
import com.gduf.lsm.entity.WaterBill;
import com.gduf.lsm.service.WaterBillService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告信息表前端操作接口
 **/
@RestController
@RequestMapping("/waterBill")

public class WaterBillController {

    @Autowired
    private WaterBillService waterBillService;

    /**
     * 新增
     * @param waterBill
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody WaterBill waterBill) {
        waterBillService.add(waterBill);
        return Result.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        waterBillService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        waterBillService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     * @param waterBill
     * @return
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody WaterBill waterBill) {
        waterBillService.updateById(waterBill);
        return Result.success();
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        WaterBill waterBill = waterBillService.selectById(id);
        return Result.success(waterBill);
    }

    /**
     * 查询所有
     * @param waterBill
     * @return
     */
    @GetMapping("/selectAll")
    public Result selectAll(WaterBill waterBill ) {
        List<WaterBill> list = waterBillService.selectAll(waterBill);
        return Result.success(list);
    }

    /**
     * 查询此用户的流水账
     * @param userId
     * @return
     */
    @GetMapping("/selectByUserId/{userId}")
    public Result selectByUserId(@PathVariable Integer userId){
        List<WaterBill> list=waterBillService.selectByUserId(userId);
        return Result.success(list);
    }

    /**
     * 分页查询
     * @param waterBill
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/selectPage")
    public Result selectPage(WaterBill waterBill,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<WaterBill> page = waterBillService.selectPage(waterBill, pageNum, pageSize);
        return Result.success(page);
    }

}